package com.liguo.whoisthespy.ui

import android.app.Activity
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import com.liguo.whoisthespy.R
import kotlinx.android.synthetic.main.ppw_look_over.view.*
import org.jetbrains.anko.onClick

/**
 * 查看词语
 * Created by su on 2017/6/17.
 */
class LookOverPpw(val act: Activity): PopupWindow() {
    private var state = 0//0表示用户没有确认，1表示用户已经确认
    private val pupView by lazy{
        (act.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater)
                .inflate(R.layout.ppw_look_over,null)
    }

    init {
        //设置SelectPicPopupWindow的View
        this.contentView = pupView
        //设置SelectPicPopupWindow弹出窗体的宽
        this.width = ViewGroup.LayoutParams.MATCH_PARENT
        //设置SelectPicPopupWindow弹出窗体的高
        this.height = ViewGroup.LayoutParams.MATCH_PARENT
        //设置SelectPicPopupWindow弹出窗体可点击
        this.isFocusable = true
        setBackgroundDrawable(ColorDrawable(0x00000000))

        contentView.apply {
            ppw_lo_layout.onClick { dismiss() }
            ppw_lo_context_layout.onClick {  }
            ppw_lo_queren.onClick {
                if(state==0){
                    state=1
                    ppw_lo_text.visibility=View.VISIBLE
                    ppw_lo_queren_text.visibility=View.GONE
                    ppw_lo_queren.text= "关闭"
                }else{
                    dismiss()
                }
            }
            ppw_lo_quxiao.onClick { dismiss() }
        }
    }

    fun show(parent: View?,name:String,string:String) {
        showAtLocation(parent, Gravity.BOTTOM, 0,0)
        contentView.apply {
            state=0
            ppw_lo_text.text = string
            ppw_lo_queren_text.text = "请确认你是"+name
            ppw_lo_text.visibility=View.GONE
            ppw_lo_queren_text.visibility=View.VISIBLE
            ppw_lo_queren.text= "确认"
        }

    }
}
